package br.com.wai2008.client.sintetizer;

import java.util.Date;

import br.com.wai2008.client.system.SystemCommand;

/**
 * This class calls a system command execution which perform a voice
 * sintetizer. This program is espeak.<br>
 * This class only implements an execution of Linux system commands. In order
 * to perform the correct execution, you must give 'sudo' access
 * without password to the user who will execute these command and you must 
 * have the espeak program on your machine.
 * 
 * @since 
 * 		September, 2008.
 * 
 * @version
 * 		WAI2008 - version 1.0
 * 
 * @author 
 * 		Andre Romero Goncales
 */
public class VoiceSintetizer {

	/**
	 * Calls an execution of 'espeak' command that performs a voice
	 * sintetizer on your the machine.<br>
	 * The command executed is 'sudo espeak -v (language) -a 200 (message)'.<br>
	 * In order to correctly execute this system command, give 'sudo'
	 * access to the user who will execute this command and you must 
	 * have the espeak program on your machine.
	 * 
	 * @see
	 * 		br.com.wai2008.client.system.SystemCommand
	 * 
	 * @param
	 * 		language The language used in the program.
	 * @param
	 * 		message The message to be read.
	 */
	public static void read(String language, String message) {
		if (language != null && language.length() >= 2) {
			language = language.substring(0, 2).toLowerCase();
		} else {
			language = "en";
		}
		System.out.println("[VoiceSintetizer] Speaking message...");
		String[] readThis = new String[]{"sudo", "espeak", "-v", language, "-a", "200", message};
		SystemCommand.executeSystemCommand(readThis);
	}
}
